package com.example.a2032.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;

import com.example.a2032.db.DataDbHelper;
import com.example.a2032.db.dao.BindersDao;
import com.example.a2032.db.dao.GroupsDao;
import com.example.a2032.livedatas.SingleSourceLiveData;
import com.example.a2032.entity.ImResultData;

import java.util.List;

public class BindChatViewModel extends AndroidViewModel {

    private final SingleSourceLiveData<List<ImResultData.BindersBean>> bindersBeanObservable;
    private final SingleSourceLiveData<List<ImResultData.GroupsBean>> groupsObservable;
    BindersDao bindersDao;
    GroupsDao groupsDao;

    public BindChatViewModel(@NonNull Application application) {
        super(application);
        bindersDao = DataDbHelper.getInstance().getBindersDao();
        groupsDao = DataDbHelper.getInstance().getGroupsDao();
        bindersBeanObservable = new SingleSourceLiveData<>();
        groupsObservable = new SingleSourceLiveData<>();
    }

    public LiveData<List<ImResultData.BindersBean>> getAllContact(){
        bindersBeanObservable.setSource(bindersDao.loadAllBinders());
        return  bindersBeanObservable;
    }
    public LiveData<List<ImResultData.GroupsBean>> getAllGroups(){
        groupsObservable.setSource(groupsDao.loadAllGroups());
        return  groupsObservable;
    }
}
